package com.ahwei.shop.auth.security.servcie;

import com.ahwei.shop.auth.entity.User;
import com.ahwei.shop.auth.security.entity.SecurityUser;
import com.ahwei.shop.auth.service.UserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import javax.annotation.Resource;

/**
 * @author：ahWei
 * Email: ahwei163@qq.com
 * Date: 2022-05-19 17:28:22
 * Description: 这是一个Java文件！
 */
public class UserDetailsServiceImpl implements UserDetailsService {
    @Resource
    private UserService userService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //查询用户信息
        User user = userService.registerCheck(username);
        if(user == null){
            throw new UsernameNotFoundException(String.format("用户['%s']不存在", username));
        }

        return new SecurityUser(user);
    }
}
